package io.aircraft.modules.wms.controller;

import io.aircraft.common.annotation.LogOperation;
import io.aircraft.common.utils.ProcResult;
import io.aircraft.common.utils.Result;
import io.aircraft.common.validator.ValidatorUtils;
import io.aircraft.common.validator.group.DefaultGroup;
import io.aircraft.common.validator.group.UpdateGroup;
import io.aircraft.modules.wms.dto.SimulateDTO;
import io.aircraft.modules.wms.service.SimulateService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@RestController
@RequestMapping("wms/simulate")
public class SimulateController {
    @Autowired
    private SimulateService simulateService;

    @PostMapping
    @LogOperation("设备模拟")
    @RequiresPermissions("wms:simulate")
    public Result simulate(@RequestBody SimulateDTO dto) {
        //效验数据
        ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
        ProcResult procResult = simulateService.simulateByManual(dto);
        if (procResult.getCode().equals("0")) {
            return new Result().ok(procResult.getMsg());
        }
        return new Result().error(procResult.getMsg());
    }

    @PostMapping("go")
    public Result go(@ApiIgnore @RequestBody Map<String, Object> params) {
        ProcResult procResult = simulateService.goByManual(params);
        return new Result().ok(procResult.getMsg());
    }
}
